/**
 * Created by yuwq on 2017/9/18.
 */
import * as globalTypes from '../../../mutation-types'
import dicConfig from '../../../api/config/dic-config'

/**
  * 获取字典列表
  * @param data
  * @returns {*}
 */
export const dicQueryList = ({commit, state, rootState, dispatch}, data) => {
  return dicConfig.queryDicList(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 字典配置
 * @param data
 * @returns {*}
 */
export const dicfindOneAppDic = ({commit, state, rootState, dispatch}, data) => {
  return dicConfig.findOneAppDic(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 字典复制
 * @param data
 * @returns {*}
 */
export const copyOneAppDic = ({commit, state, rootState, dispatch}, data) => {
  return dicConfig.copyOneAppDic(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 保存字典配置
 * @param data
 * @returns {*}
 */
export const dicUpdateOneAppDic = ({commit, state, rootState, dispatch}, data) => {
  return dicConfig.updateOneAppDic(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 保存字典
 * @param data
 * @returns {*}
 */
export const updateDic = ({commit, state, rootState, dispatch}, data) => {
  return dicConfig.updateDic(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 添加字典
 * @param data
 * @returns {*}
 */
export const addDic = ({commit, state, rootState, dispatch}, data) => {
  return dicConfig.addDic(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 字典导入
 * @param data
 * @returns {*}
 */

export const addDictionaryImportTask = ({commit, state, rootState, dispatch}, data) => {
  return dicConfig.addDictionaryImportTask(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 字典导入任务列表
 * @param data
 * @returns {*}
 */
export const queryDictionaryImportTask = ({commit, state, rootState, dispatch}, data) => {
  return dicConfig.queryDictionaryImportTask(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 字典导入任务删除
 * @param data
 * @returns {*}
 */
export const delDictionaryImportTask = ({commit, state, rootState, dispatch}, data) => {
  return dicConfig.delDictionaryImportTask(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
